<%@page import="com.ece.items.ItemBusinessController"%>
<%@page import="com.ece.KiwiMainBusiness"%>
<%@ page import="java.util.List"%> 
<%@ page import="java.util.ArrayList"%>
<%@ page import="java.util.Arrays"%>
<%@ page import="com.ece.beans.items.Item"%>
<%@ page import="com.ece.beans.items.Livre"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	if (session.getAttribute("urlProject")==null) { session.setAttribute("urlProject","http://localhost:8080/KiwiPresentationWeb/"); }
	if ( (session.getAttribute("connected")==null) || ( !((Boolean)session.getAttribute("connected")).booleanValue())) {
		response.sendRedirect(session.getAttribute("urlProject")+"connexion.jsp");
	}
	if ( ((ArrayList<Item>)session.getAttribute("cart")).size() == 0 ){
		response.sendRedirect(session.getAttribute("urlProject")+"index.jsp");
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>Kiwi Project - Mon Panier</title>
		<link rel="stylesheet" href="css/bootstrap.css"/>
		<link rel="stylesheet" href="css/global.css" type="text/css" media="screen" />
	</head>
	
	<body>
		<h1 class="mainTitle">Kiwi Project</h1>
		<div class="hero-unit">
			<h2>G&eacute;rer mon panier</h2>
			<br />
			<br />
			<br />
			<div class="container">
				<table class="condensed-table">
					<thead>
						<tr>
							<td></td>
							<td>Type</td>
							<td>Titre</td>
							<td>Prix</td>
						</tr>
					</thead>
					<tbody>
						<%
							if (session.getAttribute("cart") != null) { 
								ArrayList<Item> myCart=(ArrayList<Item>)session.getAttribute("cart");
								String type="N/A";
								String libelle="N/A";
								float prix=0;
								String reference="";
								for (int i=0;i<myCart.size();i++) {
									if (((String)myCart.get(i).getReference().substring(0, 1)).equalsIgnoreCase("L")) {
										type="Livre";
									}
									else {
										if (((String)myCart.get(i).getReference().substring(0, 1)).equalsIgnoreCase("D")) {
											type="DVD";
										}
									}
									reference=myCart.get(i).getReference();
									libelle=myCart.get(i).getLibelle();
									prix=myCart.get(i).getPrix();
									out.print("<tr><td><a href='removeItemServlet?itemReference="+reference+"'><img style='width:24px;height:24px;' src='delete.png'/></a></td><td>"+type+"</td><td>"+libelle+"</td><td>"+prix+"</td></tr>");
								}
							}
						%>
					</tbody>
				</table>
				<br />
				<a href="index.jsp">Revenir &agrave; l'accueil.</a>
			</div>
		</div>
		<footer>
        	<p>
        		<%
        			if (session.getAttribute("username")!=null) { 
        				out.write("Connect&eacute; en tant que "+session.getAttribute("username").toString());
        				out.write(" - <a href=\""+ session.getAttribute("urlProject") +"logout.jsp\">Se d&eacute;connecter</a>");
        			}
        		%>
       		</p>
		</footer>		
	</body>
</html>